import 'package:flutter/material.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
// 修改前
//import '../route/router.dart' as router;
// 修改后
import '../../route/router.dart' as router;

class HomePage extends StatefulWidget {
  const HomePage({super.key});
  @override
  State<StatefulWidget> createState() {
    return _HomePageState();
  }
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            SizedBox(
              width: double.infinity,
              height: 150,
              child: Swiper(
                itemCount: 3,
                autoplay: true,
                pagination: const SwiperPagination(),
                itemBuilder: (context, index) {
                  return Container(
                    color: Colors.red,
                    height: 150,
                    width: double.infinity,
                    margin: EdgeInsets.all(15),
                  );
                },
              ),
            ),
            Expanded(
              child: ListView.builder(
                itemBuilder: (context, index) {
                  return _listItemView();
                },
                itemCount: 10,
              ),
            ),

            Text('Home Page'),
            Text('Home Page'),
            Text('Home Page'),
            Text('Home Page'),
          ],
        ),
      ),
    );
  }

  Widget _listItemView() {
    //GestureDetector()无点击效果点击事件   InWell() 有点击效果
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(
          context,
          router.RouterPath.webViewPage,
          arguments: "https://www.baiduaa.com",
        );
      }, //点击事件
      child: Container(
        margin: EdgeInsets.only(top: 10, left: 15, right: 15),
        padding: EdgeInsets.all(10),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.red, width: 1),
          borderRadius: BorderRadius.circular(10),
        ),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ClipRRect(
                  borderRadius: BorderRadius.circular(50),
                  child: Image.asset(
                    'assets/images/OIP-C.webp',
                    width: 50,
                    height: 50,
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(width: 10),
                Text(
                  "名字",
                  style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                ),
                Expanded(child: SizedBox()),
                Text(
                  "置顶",
                  style: TextStyle(
                    fontSize: 16,
                    color: Colors.red,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
            Text('Home Page'),
            Text('Home Page'),
            Row(
              children: [
                Text("Username"),
                Expanded(child: SizedBox()),
                Text("2023-08-01"),
                Expanded(child: SizedBox()),
                Image.asset('assets/images/OIP-C.webp', width: 50, height: 50),
              ],
            ),
            Text('Home Page'),
            Text('Home Page'),
          ],
        ),
      ),
    );
  }
}
